package com.lei.cookie;

import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.http.Cookie;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

public class CookieServlet extends HttpServlet {

	@Override
	protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
		req.setCharacterEncoding("UTF-8");
		req.setCharacterEncoding("UTF-8");
		
		Cookie a =new Cookie("300secnod","userName");
		a.setMaxAge(300);
		resp.addCookie(a);
		
		Cookie b =new Cookie("temp","passWord");
		resp.addCookie(b);
		
		Cookie[] cookies=req.getCookies();
		if(cookies != null) {
			for(Cookie tempCookie:cookies) {
				System.out.println("cookie name="+tempCookie.getName()+" cookie value="+tempCookie.getValue()+" domain = "+tempCookie.getDomain());
			}
		}
		resp.getWriter().println("helloWorld");
	}


}
